using NHibernate;
using NHibernate.Cfg;

namespace Project.Library.NHibernate
{
    /// <summary>
    /// Configures NHibernate and create a session
    /// </summary>
    class NHSessionFactory : INHSessionFactory {

        private readonly ISessionFactory sessionFactory;

        /// <summary>
        /// Initializes a new instance of the <see cref="NHSessionFactory"/> class.
        /// </summary>
        public NHSessionFactory()
        {
            var configuration = new Configuration().Configure();
            sessionFactory = configuration.BuildSessionFactory();
        }

        /// <summary>
        /// Creates a session instance.
        /// </summary>
        /// <returns></returns>
        public ISession Create()
        {
            return sessionFactory.OpenSession();
        }
    }
}